package com.jiushi.redis.controller;

import com.jiushi.redis.entity.User;
import com.jiushi.redis.service.UserService;
import com.jiushi.redis.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "用户相关接口")
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("用户登录")
    @PostMapping("login")
    public Result login(@RequestBody User user){
        return Result.ok(userService.login(user));
    }

    @ApiOperation("用户注册")
    @PostMapping("register")
    public Result register(@RequestBody User user){
        return Result.ok(userService.register(user));
    }

    @ApiOperation("redis添加缓存")
    @GetMapping("testAdd/{id}")
    public User testAdd(@PathVariable Long id){
        return userService.testAdd(id);
    }

    @ApiOperation("redis删除缓存")
    @GetMapping("testDelete/{id}")
    public User testDelete(@PathVariable Long id){
        return userService.testDelete(id);
    }

}
